import string
import os
import time
import types
import socket
import cPickle
import hashlib

import simplejson as json

from bsddb3 import db

"""
    Copyright (C) 2009,2010  Jorge Alegre Vilches

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
"""

"""
Model Implementation. 
"""

class Model(object):
	"""Implements the database calls to OctopusDbm.
	
	DbmTables(Dbm)

	=================================================================
	
	get
	===
	
	With id ?????
	oClient = Client.get(Id=34)
	With primary key, either an integer of string
	oClient = Client.get(Pk='luis')
	Where with AND values
	oClient = Client.get(Place='Madrid', Name='Jorge') -> Only 1 (If not, exception NonUniqueValue, try filter)
	Must check if index exists with given values to use them to open cursor in one of them
	---->
	AttributeDict = dbm.getDirect(table, key)
	Checks that value is json and Tables format, to create a Dictionary with Attributes (Logical)
	oClient.Name = AttributeDict['Name']
	oClient.sAttr = AttributeDict[sAttr]
	
	AttributeDict = DbmTables.getByAttr(table, **AttrDict)
	==================================================================
	
	filter
	======	
	QueryList = Client.filter(Place='Madrid') [type DdmTableList]
	----->
	List = DbmTables.filter(table, **AttrDict)
	
	save
	====
	oClient.save() (I did get first)
	Client.save(Pk=23, Place='Madrid', Nombre='Luis')
	------>
	DbmTables.delete(table, **AttrDict)
	
	delete
	======
	oClient.delete()
	Client.delete(Pk=23)
	Client.delete(Place='Madrid', Name='Jorge')
	---->	
	
	save (Lists)
	============
	Server will open tables and do put(). If Pk informed and exists, then get() and put() with attributes informed.
	
	ClientQueryList.save() (Did filter() first)
	---->
	DbmTables.putListDirect()
	
	QueryList = []
	oClient1 = Client(Place='Madrid', Name='Carlos')
	oClient1 = Client(Pk=23, Place='Madrid', Name='Carlos')
	QueryList.append(oClient1)
	QueryList.save()
	"""	
	def __init__(self):
		pass
	def save(self):
		pass
	def get(self):
		pass
	def filter(self):
		pass
	def delete(self):
		pass
	def saveList(self):
		pass

class CharField(object):
	"""Doc."""
	def __init__(self):
		pass

class IntegerField(object):
	"""Doc."""		
	def __init__(self):
		pass

class DateField(object):
	"""Doc."""
	def __init__(self):
		pass

class BooleanField(object):
	"""Doc."""
	def __init__(self):
		pass

class FloatField(object):
	"""Doc."""
	def __init__(self):
		pass

class PrimaryKeyField(object):
	"""Doc. ?????????????????"""
	def __init__(self, bId=True):
		pass

class QueryList(list, Model):
	"""Doc."""
	def __new__(self):
		pass
	"""Doc."""
	def saveList(self):
		pass
